Helpful Information
 
 
Category: mod_rewrite
mod_rewrite => It doesn't pass my variables from page to page.

Environment:
Kernel/2.4.2-2
Apache/1.3.19
Distro/RH7.1

.htaccess-file:
RewriteEngine On
RewriteRule ^news/([0-9]+) news.php?nid=$1 [T=application/x-httpd-php]
RewriteRule ^news$ index.php

MySQL query:
$result = mysql_query("SELECT * FROM news where nid = '$nid'");

What I'm trying to do:
On the front page, there's a box with news, wich contains a synopsis, and reader will have to press a "read more" link to get the rest. Before I came across mod_rewrite I used news.php?nid=$nid, but now I want to use news/$nid - I've gotten the page to work with all images and such displaying as they should. But the variable $nid isn't passed through to the news.php page where I display the rest of the news... I've tried to echo out $nid and it comes out blank. Please help? :)

RewriteEngine On
RewriteRule ^news/([0-9]+)$ /server/path/to/news.php?nid=$1 [T=application/x-httpd-php,L]
RewriteRule ^news/?$ index.php [R,L]

Nope.. still not working :(

1) Where is your index.php?
2) Where is your .htaccess?
3) Do you have write access to httpd.conf?

>> still not working
4) What page did you get in return?

>> 1) Where is your index.php?

In the same folder where news.php is
/www/htdocs/adfS/www.hypothetic.net/index.php news.php

>> 2) Where is your .htaccess?
/www/htdocs/adfS/www.hypothetic.net/.htaccess

>> 3) Do you have write access to httpd.conf?
Yes

>> 4) What page did you get in return?
news.php without the news. I've also
added echo ("blah $nid"); so that I can see if $nid is true..

Remove the 2nd RewriteRule line.

Just use:

RewriteRule ^news/([0-9]+)$ /www/htdocs/adfS/www.hypothetic.net/news.php?nid=$1 [T=application/x-httpd-php,L]

Since you have access to httpd.conf, why don't you do all this in <Directory "/www/htdocs/adfS/www.hypothetic.net"> ?

You also can enable RewriteLog like so:

RewriteEngine on
RewriteLog /var/log/apache/rewrite_log
RewriteLogLevel 9

>> Remove the 2nd RewriteRule line.
Done

>> Just use: RewriteRule ^news/([0-9]+)$ /www/htdocs/adfS/www.hypothetic.net/news.php?nid=$1 [T=application/x-httpd-php,L]
Done

>> Since you have access to httpd.conf, why don't you do all this in <Directory "/www/htdocs/adfS/www.hypothetic.net"> ?
Done (didn't know that was a way)

>> You also can enable RewriteLog like so:

RewriteEngine on
RewriteLog /var/log/apache/rewrite_log
RewriteLogLevel 9
Tried that, got an error stating that RewriteLog wasnt allowed there.

>> Tried that, got an error stating that RewriteLog wasnt allowed there

Define the following lines globally:

RewriteEngine on
RewriteLog /var/log/apache/rewrite_log
RewriteLogLevel 9

Within the <Directory> block, put:

RewriteEngine on
RewriteOptions inherit
RewriteRule ^news/([0-9]+)$ /www/htdocs/adfS/www.hypothetic.net/news.php?nid=$1 [T=application/x-httpd-php,L]

BTW, the ruleset should work and there is no need to enable RewriteLog.

Define the following lines globally:

RewriteEngine on
RewriteLog /var/log/apache/rewrite_log
RewriteLogLevel 9Done

Within the <Directory> block, put:

RewriteEngine on
RewriteOptions inherit
RewriteRule ^news/([0-9]+)$ /www/htdocs/adfS/www.hypothetic.net/news.php?nid=$1 [T=application/x-httpd-php,L]Done

BTW, the ruleset should work and there is no need to enable RewriteLog. [/B]Hmm.. perhaps I've installed it wrong..
I just recompiled apache with --enable-module=most...
And restarted it..

Do you have ICQ or something? irc maybe...?
It'll be alot easier that way..

If you won't display yours, I can just display mine;
ICQ: 108045292
irc: sam\ @ EFnet

Anyway, this is the logfile created:
http://www.hypothetic.net/rewrite_log - It's kinda long so I posted the file instead.. hope you don't mind.

You need to put the Rewrite lines within <Directory> of the actual file system path, no symlink. That said, this path:

/www/htdocs/adfS/www.hypothetic.net

can't be symlink.

All you need to do is to access it like http://www.hypothetic.net/news/123, which matches news/([0-9]+)$, then it will take 123 to $1.

Here is what the rewrite log should look like:

add path-info postfix: /www/htdocs/adfS/www.hypothetic.net/news -> /www/htdocs/adfS/www.hypothetic.net/news/123
strip per-dir prefix: /www/htdocs/adfS/www.hypothetic.net/news/123 -> news/123
applying pattern '^news/([0-9]+)$' to uri 'news/123'
rewrite news/123 -> /www/htdocs/adfS/www.hypothetic.net/news.php?nid=123
news.php?nid=123 -> uri=/www/htdocs/adfS/www.hypothetic.net/news.php, args=nid=123
remember /www/htdocs/adfS/www.hypothetic.net/news.php to have MIME-type 'application/x-httpd-php'
strip document_root prefix: /www/htdocs/adfS/www.hypothetic.net/news.php -> /news.php
internal redirect with /news.php [INTERNAL REDIRECT]

You also can do a search under my username with the keyword RewriteRule in this forum. I have posted many examples for your situation.

In the rewrite_log that you posted, the lines are too far off and nowhere near. You need to check and make sure the paths are correct. I suggest you start off with another file name like news1.php instead of news.php. In news1.php, just put something simple like so:

<?php
echo $QUERY_STRING;
?>

You need to put the Rewrite lines within <Directory> of the actual file system path, no symlink. That said, this path:

/www/htdocs/adfS/www.hypothetic.net

can't be symlink.I'm sorry, I don't understand what you mean by this.. perhaps you can provide me with an example?


You also can do a search under my username with the keyword RewriteRule in this forum. I have posted many examples for your situation.That I will do. Thanks for your patience and quick responses.

>> perhaps you can provide me with an example?

I posted so many examples that I can't even remember which one would be appropriate. Check this one out (a little more complicated than yours) ->
http://forums.devshed.com/showthread.php?s=&threadid=18661&forumid=15&highlight=RewriteRule

Hmm.. I ment an example on what should be in httpd.conf...
This is what I have now:

RewriteEngine on
RewriteLog /www/logs/rewrite_log
RewriteLogLevel 9

<Directory "/www/htdocs/adfS/www.hypothetic.net">
RewriteEngine on
RewriteOptions inherit
RewriteRule ^news/([0-9]+)$ /www/htdocs/adfS/www.hypothetic.net/news.php?nid=$1 [T=application/x-httpd-php,L]

Options Indexes FollowSymLinks MultiViews
AllowOverride FileInfo
Order allow,deny
Allow from all
</Directory>

I figure there's something wrong since it doesn't work.. maybe you know what?

Comparing your rewrite_log with mine (I posted in my previos post), it appears that you have set your path incorrectly right at the strip per-dir prefix line.
Whenever you see a Passthru, that means the pattern doesn't match. Therefore, yours never reached rewrite news/123 line.

Please use a new php script like news1.php so you can see what's going on easier.

BTW, if you don't know what MultiViews is for, don't enable it. Maybe when you are accessing http://www.hypothetic.net/news and Apache think it should be www.hypothetic.net/news.php and automatically append the php extension. So mod_rewrite didn't go further enough and passthru.

MultiViews had many critical exploits in the past, even in 1.3.20. In 1.3.22, MultiViews is broken.

BTW, if you don't know what MultiViews is for, don't enable it. Maybe when you are accessing http://www.hypothetic.net/news and Apache think it should be www.hypothetic.net/news.php and automatically append the php extension. So mod_rewrite didn't go further enough and passthru.

MultiViews had many critical exploits in the past, even in 1.3.20. In 1.3.22, MultiViews is broken. Yeah! I removed MultiViews and it worked! I didn't know what it was for, but it was on another <Directory> section... Anyway, thanks alot for your patience in this matter!

The RewriteLog lines is for debugging purpose. So be sure to remove it when your script is done.

BTW, here is my very own standard of docroot layout:

Default server:

docroot -> /www/htdocs
cgi-bin -> /www/cgi-bin

vhost.com:

docroot -> /www/vhosts/vhosts.com/htdocs
cgi-bin -> /www/vhosts/vhosts.com/cgi-bin

Next time you are going to reinstall Apache or your server, create a unique /www partition. Having a unique partition to serve webpage increases performance and I/O speed.










privacy (GDPR)